package com.meyoung.day3;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class sendemailTest {
    WebDriver driver;

    @BeforeMethod
    public void openchromeTest01(){
        //设置chromedriver路径
        System.setProperty("webdriver.chrome.driver", "C:\\Users\\cll520\\IdeaProjects\\selenium11\\drivers\\chromedriver.exe");
        //实例化Chromedriver
        driver = new ChromeDriver();
        driver.get("https://mail.163.com/");
    }
    @Test
    public void Sendemail() throws InterruptedException {
        LoginTest.login(driver,"a969117645","cll930304");
        //显示等待
        WebDriverWait wait = new WebDriverWait(driver,10);
        wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"dvNavTop\"]/ul/li[2]")));
        //定位到写信按钮，点击
        driver.findElement(By.xpath("//*[@id=\"dvNavTop\"]/ul/li[2]/span")).click();
        Thread.sleep(5000);
        //定位到收件人，输入收件人邮箱
        driver.findElement(By.xpath("//*[@aria-label=\"收件人地址输入框，请输入邮件地址，多人时地址请以分号隔开\"]")).sendKeys("a969117645");
        //定位到主题，输入主题
        Thread.sleep(5000);
        driver.findElement(By.xpath("//*[@aria-label=\"邮件主题输入框，请输入邮件主题\"]/input")).sendKeys("这是一个主题");
        //添加附件
        //Thread.sleep(5000);
        //driver.findElement(By.xpath("//*[@title=\"一次可发送2000张照片，600首MP3，一部高清电影\"]")).sendKeys("C:\\Users\\123\\Pictures\\IMG_00000150_tmp_tmp.jpg");
        Thread.sleep(5000);
        WebElement frame = driver.findElement(By.className("APP-editor-iframe"));
        //driver控制权转交
        driver.switchTo().frame(frame);
        Thread.sleep(5000);
        //定位输入框，输入内容
        driver.findElement(By.xpath("/html/body")).sendKeys("这是一个内容");
        //转交回driver
        driver.switchTo().defaultContent();
        Thread.sleep(5000);
        //定位发送，点击
        driver.findElement(By.xpath("//*[text()=\"发送\"]")).click();


    }
    @AfterMethod
    public void clsedBrowser(){
        driver.quit();
    }
}
